package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 游记
 */
@Setter
@Getter
public class Travel extends BaseDomain{
    public static final int STATUS_COMMON = 0;//草稿
    public static final int STATUS_AUDIT = 1;//审核
    public static final int STATUS_RELEASE = 2;//发布
    public static final int STATUS_HOT = 3;//发布
    public static final int STATUS_REFUSE = -1;//拒绝
    //标题
    private String title;
    //旅游时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date travelTime;
    //人均消费
    private String perExpends;
    //旅游天数
    private Integer days;
    //和谁来旅游
    private Integer person;
    //作者
    private User author;
    //创建时间
    private Date createTime;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;
    //最后更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;
    //是否公开
    private Boolean isPublic = false;//默认为不发布
    //旅游地区
    private Region place;
    //封面
    private String coverUrl;
    //状态
    private Integer state = STATUS_COMMON;//默认为草稿
    private Travelcontent travelcontent;//游记内容
    //获取状态名称
    public String getStateName(){
        String msg = "草稿";
        if (STATUS_AUDIT == state){
            msg = "待审核";
        }else if (STATUS_RELEASE == state){
            msg = "已发布";
        }else if (STATUS_HOT == state){
            msg = "推荐";
        }else if (STATUS_REFUSE == state){
            msg = "已拒绝";
        }
        return msg;
    }

    //获取出行同伴
    public String getPersonName(){
        String msg = "和其他人";
        if (1 == person){
            msg = "一个人的旅行";
        }else if (2 == person){
            msg = "和父母";
        }else if (3 == person){
            msg = "和朋友";
        }else if (4 == person){
            msg = "和同事";
        }else if (5 == person){
            msg = "和爱人";
        }
        return msg;
    }
    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }
}